package edu.hcnu.server.impl;

import edu.hcnu.domain.User;
import edu.hcnu.mapper.BankMapper;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.transaction.annotation.Transactional;

public class BankServer {

    private BankMapper bankMapper;

    public BankServer(SqlSessionTemplate sqlSession) {
        bankMapper = sqlSession.getMapper(BankMapper.class);
    }

    @Transactional
    public void transfer(User a, User b, int money) {
        bankMapper.update(a.getName(), money);
//        int i = 1 / 0;
        bankMapper.update(b.getName(), -money);
    }
}
